<?php
/**
 * Created by JetBrains PhpStorm.
 * User: thinhhung
 * Date: 6/1/12
 * Time: 3:16 PM
 * To change this template use File | Settings | File Templates.
 */
//echo "chitietban";
$mahdb = $this->Session->read('MAHDB');

?>
<h1 align="center">CHI TIẾT HÀNG HÓA BÁN</h1>

<script>
    /* $(document).ready(function () {
       $('#ChiTietBanSANPHAMID').change('input', function () { //bind
           alert($(this).val());
           $v = $(this).val();

       });
   }); */

    /* $(document).ready(function () {
       $('#ChiTietBanSANPHAMID').change('input', function () {
           alert($(this).val());
           $.ajax({
               url:'/banhang/chi_tiet_bans/index',
               type:"GET",
               data:{term:$(this).val()
               },
               success:function (data) {
                   //$('#result').val(data);
                   //alert(data);

                   $('#result').html(data);
                   alert(data);

               }
           }).fail(function () {
                   alert("error");
               })
               .always(function () {
                   alert("complete");
               });
       });
   }); */


</script>

<div id="form">
    <?php echo $this->Form->create('ChiTietBan', array('action' => 'add', $mahdb));?>
    <fieldset>
        <legend><?php ('Send Message'); ?></legend>
        <?php echo $this->Form->input('id', array('type' => 'hidden', 'style' => 'width:200px')); ?>
        <dl>
            <dt><label>Mã hóa đơn bán</label></dt>
            <dd><?php echo $this->Form->input('MAHDB', array('label' => false, 'value' => $mahdb, 'readonly' => true)); ?></dd>
        </dl>
        <dl>
            <dt><label>Mã hàng hóa</label></dt>
            <dd><?php echo $this->Form->input('MASP', array('label' => false)); ?></dd>
        </dl>
        <dl>
            <dt><label>Số lượng</label></dt>
            <dd><?php echo $this->Form->input('SLBAN', array('label' => false)); ?></dd>
        </dl>

         <?php echo $this->Form->input('DONGIABAN', array('type' => 'hidden')); ?>

        <?php
        echo $this->Form->submit('Thêm hàng hóa', array('style' => 'margin-left: 16.5em'));
        echo $this->Form->end();
        ?>
    </fieldset>
    <?php
    //echo $this->Form->end(__('Submit', true)); //submit khong su dung ajax
    //echo $Ajax->submit('Submit',array('url'=>'/bans/add','update'=>'messages'));


    ?>
</div>
<div id="view">
    <?php
    //echo "value : " . $this->Js->get('#ChiTietBanSANPHAMID');
    //echo $this->Html->link('Thêm hàng hóa bán', array('controller' => 'bans', 'action' => 'add'));
    echo "<br /><br />";
    ?>
    <div style="font-size: large;">
        <?php // echo 'MÃ HÓA ĐƠN NHẬP : ' .$temps;
        ?>
    </div>
    <br/>
    <table>
        <tr>

            <th><?php echo $this->Paginator->sort('MASP', 'MÃ HÀNG HÓA'); ?></th>
            <th><?php echo $this->Paginator->sort('SLBAN', 'SỐ LƯỢNG'); ?></th>
            <th><?php echo $this->Paginator->sort('DONGIABAN', 'ĐƠN GIÁ BÁN (VNĐ)'); ?></th>
            <th>THAY ĐỔI</th>
        </tr>

        <?php foreach ($bans as $ban): ?>
        <tr>
            <!-- <td><php echo $ban['Nhap']['MaHDNhap']; ?></td> -->
            <td><?php echo $ban['ChiTietBan']['MASP']; ?></td>
            <!-- $this->Html->link($hanghoa['HangHoa']['TenHG'],
 //    array('controller' => 'hanghoas', 'action' => 'view', $hanghoa['HangHoa']['TenHG'])) -->
            <td><?php echo $ban['ChiTietBan']['SLBAN']; ?></td>
            <td><?php echo $ban['ChiTietBan']['DONGIABAN']; ?></td>
            <td><?php //echo $this->Html->link('Sửa', array('action' => 'index', $ban['Ban']['MaHG']));
                if ($this->Session->read('quyen') != 'nhanvien') {
                    echo $this->Html->link($this->Html->image('/images/user_edit.png'), array('action' => 'edit', $ban['ChiTietBan']['id']), array('escape' => false));
                }  else echo '&nbsp';?>
                <?php
                if ($this->Session->read('quyen') == 'quantri') {
                    echo $this->Html->link($this->Html->image('/images/trash.png'), array('action' => 'delete', $ban['ChiTietBan']['id']),
                        array('confirm' => 'Bạn có chắc muốn xóa?', 'escape' => false));
                } ?>

            </td>
        </tr>
        <?php endforeach; ?>
    </table>

    <div class="paging">
        <?php echo $this->Paginator->first('Trang đầu'); ?>
        <?php echo $this->Paginator->prev('<<' . __('Lùi', true),
        array(), null, array('class' => 'disabled')); ?>
        <?php echo $this->Paginator->numbers(); ?>
        <?php echo $this->Paginator->next(__('Tới', true) . '>>',
        array(), null, array('class' => 'disabled')); ?>
        <?php echo $this->Paginator->last('Trang cuối'); ?>
    </div>
</div>
<div id="dongds" align="center">
    <?php
    //echo $this->Html->link('ĐÓNG DANH SÁCH HÀNG HÓA', array("controller" => 'hoa_don_bans'), array('class' => 'lk'));
    echo $this->Html->link('ĐÓNG DANH SÁCH HÀNG HÓA', array("controller" => 'hoa_don_bans', 'action' => 'view', $mahdb), array('class' => 'cancel', 'target' => '_blank'));
    ?>
</div>
